﻿var $AdministratorLayout;
if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.Admin == "undefined") Axis.Admin = {};
Axis.Admin.Main = {
    Init: function () {
        var thisObj = this;
        thisObj.Layout.Init();

        thisObj.EventClick();
        setTimeout(function () {
            thisObj.GetAdminCategory();
        }, 1000);
    },
    Layout: {
        Instance: null,
        Init: function () {
            var thisObj = this;
            var options = {
                north: {
                    size: 136,
                    spacing_closed: 0,
                    spacing_open: 0,
                    showOverflowOnHover: true
                },
                east: {
                    initClosed: true
                },
                south: {
                    initClosed: true,
                    spacing_closed: 0
                },
                west: {
                    initClosed: true,
                    spacing_closed: 0
                }
            };
            thisObj.Instance = $('body').layout(options);
        }
    },
    Navigation: {
        ID: '#mega-menu-tut',
        Init: function () {
            var thisObj = this;
            $(thisObj.ID).dcMegaMenu({
                rowItems: '3',
                speed: 'fast'
            });
        }
    },
    EventClick: function () {
        var thisObj = this;
        $("#north-toggle").hover(function () {
            $(this).addClass("ui-layout-toggler-north-hover");
        }, function () {
            $(this).removeClass("ui-layout-toggler-north-hover");
        });
        $("#north-toggle").click(function (e) {
            if ($(this).hasClass("ui-layout-toggler-north-open")) {
                $("#north-toggle").removeClass("ui-layout-toggler-north-open");
                $("#north-toggle").addClass("ui-layout-toggler-north-closed");
                $(".main-header").hide();

                thisObj.Layout.Instance.sizePane('north', 46);
            }
            else {
                $("#north-toggle").removeClass("ui-layout-toggler-north-closed");
                $("#north-toggle").addClass("ui-layout-toggler-north-open");
                $(".main-header").show();
                thisObj.Layout.Instance.sizePane('north', 136);
            }
            $(window).trigger("resize");
            e.stopPropagation();
        });
    },
    GetAdminCategory: function (callback) {
        var thisObj = this;
        $("#mega-menu-tut").find("a[code]").attr("menuid", -1);
        /*     $.Ajax({
        url: '../../Views/Accounts/Service/UserService.ashx',
        type: 'POST',
        data: {
        Action: "GetAdminCategory",
        FunctionCode: "AdminCategory"
        },
        success: function (data, textStatus, jqXHR) {
        if (data) {
        data = eval("(" + data + ")");

        $.each(data, function (index, item) {
        var code = $.trim(item.Code);
        $("#mega-menu-tut").find("a[code='" + code + "']").attr("menuid", item.ID);
        });

        }
        $("#mega-menu-tut").find("a[code][menuid='-1']").parent().addClass("hidden");
        setTimeout(function () {
        thisObj.Navigation.Init();
        }, 500);

        var loc_href = window.location.href;
        var arrForbid = [];
        $("#mega-menu-tut").find("a[code][menuid='-1']").each(function () {
        var href = $(this).attr("href");
        if (href) {
        href = href.replace("../../", "");
        }
        arrForbid.push(href);
        });
        $.each(arrForbid, function (index, value) {
        if (loc_href.indexOf(value) != -1) {
        alert("Bạn không có quyền truy cập trang này.");
        location.href = "../../Views/Home";
        }

        });
        },
        beforeSend: function (jqXHR, settings) {
        },
        error: function (jqXHR, textStatus, errorThrown) {
        },
        complete: function (XMLHttpRequest, textStatus) {
        }
        });
        }




        */
        var pCodePage = 0;
        if (typeof CodePage != 'undefined')
            pCodePage = CodePage;
        var pData = {
            Action: "GetAdminCategory",
            FunctionCode: "AdminCategory"
        }
        $.ajax({
            url: '../../Views/Accounts/Service/MemberService2.asmx/GetListData',
            type: 'POST',
            data: JSON.stringify(pData),
            cache: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (objData, textStatus, jqXHR) {
                if (objData) {
                    var data = eval("(" + objData.d + ")");
                    $.each(data, function (index, item) {
                        var code = $.trim(item.Code);
                        $("#mega-menu-tut").find("a[code='" + code + "']").attr("menuid", item.ID);
                    })

                }
                $("#mega-menu-tut").find("a[code][menuid='-1']").parent().addClass("hidden");
                setTimeout(function () {
                    thisObj.Navigation.Init();
                }, 500);

                var loc_href = window.location.href;
                var arrForbid = [];
                $("#mega-menu-tut").find("a[code][menuid='-1']").each(function () {
                    var href = $(this).attr("href");
                    if (href) {
                        href = href.replace("../../", "");
                    }
                    arrForbid.push(href);
                });
                $.each(arrForbid, function (index, value) {

                    if (loc_href.indexOf(value) != -1) {
                    //    debugger;
                        alert("Bạn không có quyền truy cập trang này.");
                        location.href = "../../Views/Home";
                    }

                });
            },
            beforeSend: function (jqXHR, settings) {
            },
            error: function (jqXHR, textStatus, errorThrown) {
            },
            complete: function (XMLHttpRequest, textStatus) {
            }
        });

    }
}
$(function () {
    Axis.Admin.Main.Init();
});